package com.ruoyi.api.client.service.impl;

import com.ruoyi.api.client.domain.dto.UmsUserDto;
import com.ruoyi.api.client.service.IClientUmsService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.satoken.StpClientUtil;
import com.ruoyi.ums.domain.UmsUser;
import com.ruoyi.ums.service.IUmsUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zouhuu
 * @description 客户端用户模块 服务层
 * @date 2022/08/01 21:59:00
 */
@Service
public class ClientUmsServiceImpl implements IClientUmsService {

    @Autowired
    private IUmsUserService umsUserService;

    /**
     * 用户信息
     * @return
     */
    @Override
    public R userInfo() {
        UmsUser umsUser = umsUserService.selectUmsUserById(StpClientUtil.getLoginIdAsLong());
        return R.ok(umsUser);
    }

    /**
     * 用户信息保存
     * @param umsUserDto
     * @return
     */
    @Override
    public R userSave(UmsUserDto umsUserDto) {
        UmsUser umsUser = new UmsUser();
        BeanUtils.copyBeanProp(umsUser, umsUserDto);
        umsUser.setId(StpClientUtil.getLoginIdAsLong());
        umsUserService.updateUmsUser(umsUser);
        return R.ok("用户信息保存成功");
    }
}
